package com.ruoyi.web.controller.qsng;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.qsng.domain.KActivityCollect;
import com.ruoyi.qsng.service.IKActivityCollectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 活动收藏Controller
 *
 * @author kanglou
 * @date 2023-06-07
 */
@Api(tags = "pc--活动收藏Controller")
@RestController
@RequestMapping("/qsng/activityCollect")
public class KActivityCollectController extends BaseController {
    @Autowired
    private IKActivityCollectService kActivityCollectService;

    /**
     * 查询活动收藏列表
     */
    @ApiOperation(value = "查询活动收藏列表")
    @PreAuthorize("@ss.hasPermi('qsng:activityCollect:list')")
    @GetMapping("/list")
    public TableDataInfo list(KActivityCollect kActivityCollect) {
        startPage();
        kActivityCollect.setIsCollect((long) 1);
        List<KActivityCollect> list = kActivityCollectService.selectKActivityCollectList(kActivityCollect);
        return getDataTable(list);
    }

    /**
     * 导出活动收藏列表
     */
    @ApiOperation(value = "导出活动收藏列表")
    @PreAuthorize("@ss.hasPermi('qsng:activityCollect:export')")
    @Log(title = "活动收藏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KActivityCollect kActivityCollect) {
        List<KActivityCollect> list = kActivityCollectService.selectKActivityCollectList(kActivityCollect);
        ExcelUtil<KActivityCollect> util = new ExcelUtil<KActivityCollect>(KActivityCollect.class);
        util.exportExcel(response, list, "活动收藏数据");
    }

    /**
     * 获取活动收藏详细信息
     */
    @ApiOperation(value = "获取活动收藏详细信息")
    @PreAuthorize("@ss.hasPermi('qsng:activityCollect:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(kActivityCollectService.selectKActivityCollectById(id));
    }

    /**
     * 新增活动收藏
     */
    @ApiOperation(value = "新增活动收藏")
    @PreAuthorize("@ss.hasPermi('qsng:activityCollect:add')")
    @Log(title = "活动收藏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KActivityCollect kActivityCollect) {
        return toAjax(kActivityCollectService.insertKActivityCollect(kActivityCollect));
    }

    /**
     * 修改活动收藏
     */
    @ApiOperation(value = "修改活动收藏")
    @PreAuthorize("@ss.hasPermi('qsng:activityCollect:edit')")
    @Log(title = "活动收藏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KActivityCollect kActivityCollect) {
        return toAjax(kActivityCollectService.updateKActivityCollect(kActivityCollect));
    }

    /**
     * 删除活动收藏
     */
    @ApiOperation(value = "删除活动收藏")
    @PreAuthorize("@ss.hasPermi('qsng:activityCollect:remove')")
    @Log(title = "活动收藏", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(kActivityCollectService.deleteKActivityCollectByIds(ids));
    }
}
